const db = uniCloud.database()
let getDeviceUUID = function() {
	let deviceId = uni.getStorageSync('uni_deviceId') ||
		uni.getSystemInfoSync().deviceId ||
		uni.getSystemInfoSync().system + '_' + Math.random().toString(36).substr(2);

	uni.setStorageSync('uni_deviceId', deviceId)
	return deviceId;
}

let getQueryString = function(url, name) {
	console.log("url = " + url)
	console.log("name = " + name)
	let durl = decodeURIComponent(url)
	var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
	var r = durl.substr(1).match(reg)
	if (r != null) {
		console.log("r = " + r)
		console.log("r[2] = " + r[2])
		return r[2]
	}
	return null;
}
let timestampToTime = function(timestamp) {
	if (!timestamp) {
		return
	}
	var date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
	var Y = date.getFullYear() + '-';
	var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
	var D = date.getDate() + ' ';
	var h = date.getHours() + ':';
	var m = date.getMinutes() + ':';
	var s = date.getSeconds();
	return Y + M + D + h + m + s;
}
let userIdToName = async function(id) {
	let uName = ''
	let res =  await db.collection('uni-id-users')
		.where({
			_id: '60732c635f2dbd0001d537c3'
		})
		.get({
			getOne: true
		})
		return res.result.data.username
	console.log(88888,res.result.data.username)	
}
module.exports = {
	getQueryString: getQueryString,
	getDeviceUUID: getDeviceUUID,
	timestampToTime,
	userIdToName
}
